package com.ycw.controller.guoguo;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ycw.bean.Users;
import com.ycw.service.guoguo.PersonalCenterService;
import com.ycw.util.Msg;
/**
 * 个人中心功能controller
 * @author gcz
 *
 */
@Controller
public class PersonalCenterController {
	
	@Autowired
	private PersonalCenterService personalCenterService;
	
	/**
	 * 我发起的项目
	 * 
	 * 从session中区登录对象的id 
	 * 查看我所有的发起项目（封装项目类型）
	 * @return 
	 */
	@RequestMapping("getMyInitiateProjects")
	@ResponseBody
	public Msg getMyInitiateProjects(@RequestParam(defaultValue="1")Integer pageNum, HttpSession httpSession){
		return personalCenterService.getMyInitiateProjects(pageNum, httpSession);
	}
	
	/**我参与的项目
	 * 
	 * 从session中取登录对象的id 
	 * 
	 * 根据funding表找到Projects表
	 * @return 
	 */
	@RequestMapping("getMyParticipateProjects")
	@ResponseBody
	public Msg getMyParticipateProjects(HttpSession httpSession){
		return personalCenterService.getMyParticipateProjects(httpSession);
	}
	
	/**
	 * 我的评论
	 * 
	 * 从session中取登录对象的id 
	 * 根据Comments表找到
	 * @return
	 */
	@RequestMapping("getMyComments")
	@ResponseBody
	public Msg getMyComments(HttpSession httpSession){
		return personalCenterService.getMyComments(httpSession);
	}
	
	/**
	 * 我的私信
	 * 
	 * 从session中取登录对象的id 
	 * 根据letter表找到
	 * @return
	 */
	@RequestMapping("getMyletter")
	@ResponseBody
	public Msg getMyletter(HttpSession httpSession) {
		return personalCenterService.getMyletter(httpSession);
		
	}
	
	/**
	 * 个人资料
	 * 从session中取
	 * @return
	 */
	@RequestMapping("getMyUsers")
	@ResponseBody
	public Msg getMyUsers(HttpSession httpSession) {
		return personalCenterService.getMyUsers(httpSession);
	}
	
	/**
	 * 修改密码
	 * 
	 * 从session中取登录对象的id和原密码
	 * 
	 * 现有的密码不能和新密码重复
	 * 
	 * @param users中只有密码
	 * @return
	 */
	@RequestMapping("alertMyPassword")
	@ResponseBody
	public Msg alertMyPassword(HttpSession httpSession, Users users) {
		return personalCenterService.alertMyPassword(httpSession, users);
	}
}
